home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / fonts / mvpsf.lha / MvPSF1_4 / MvPSF.c < prev    next >
C/C++ Source or Header  |  1996-04-10  |  25KB  |  853 lines

  1. /*
  2.     lc -Lcdv -O -ma -rr -ignu:os-include MvPSF
  3.     apf -v gcc -g MvPSF.c -o MvPSF_pure -noixemul -lauto
  4.     gcc020 -o MvPSF_gcc -noixemul -m68030 MvPSF.c -lauto -g -v
  5.     gcc020 -DAPURIFY -g MvPSF.c -o MvPSF.s -m68030 -noixemul -lauto -S
  6.     Apurify -tb MvPSF.s -o MvPSFPure.s
  7.     gcc020 -g MvPSFPure.s -o MvPSF_pure -m68030 -noixemul -lauto -lAPur
  8. */
  9.  
  10. #define __MA_VERSION__ "$Revision: 1.4 $ $Date: 1996/04/10 21:30:16 $"
  11. static char MvPSF_RCS_Main[] = "$Id: MvPSF.c,v 1.4 1996/04/10 21:30:16 Christophe_Labouisse Exp $";
  12.  
  13. /* === Section : Includes === */
  14.  
  15. #include <string.h>
  16. #include <ctype.h>
  17. #include <dos/dos.h>
  18. #include <dos/rdargs.h>
  19. #include <proto/dos.h>
  20. #include <exec/exec.h>
  21. #include <exec/lists.h>
  22. #include <exec/nodes.h>
  23. #include <exec/memory.h>
  24. #include <proto/exec.h>
  25. #include <clib/alib_protos.h>
  26. #include <utility/tagitem.h>
  27. #ifdef __GNUC__
  28. #include <inline/exec.h>
  29. #include <inline/dos.h>
  30. #include <inline/alib.h>
  31. #else
  32. #include <pragmas/exec.h>
  33. #include <pragmas/dos.h>
  34. #endif
  35.  
  36.  
  37. /* === Section : Types === */
  38.  
  39. typedef enum {TYF_ERR = -1,TYF_NON = 0,TYF_AFM,TYF_PFA,TYF_PFB} TYPE_FICHIER;
  40.  
  41.  
  42. typedef struct
  43. {
  44.     struct MinNode UF_Node;
  45.     int PosDebut;       /* début de la partie textuelle */
  46.     char fontname[32];  /* chaîne de reconnaissance de FontName */
  47.     char finhead[32];   /* chaîne indiquant la fin de l'en-tête */
  48.     char type[16];      /* Extension du fichier */
  49.     char nom[108];      /* Nom du fichier */
  50.     BPTR repertoire;    /* Un "Lock" vers le répertoire où se trouve le fichier */
  51. } Un_Fichier;
  52.  
  53.  
  54. typedef struct
  55. {
  56.     char **fichiers;
  57.     LONG verbose,all,stat;
  58. } MvPSF_Args;
  59.  
  60.  
  61. typedef struct
  62. {
  63.     BOOL verbose,all,stat;
  64.     LONG nb_fic_lus,nb_dir_lues;
  65.     LONG nb_AFM;
  66.     LONG nb_PFB;
  67.     LONG nb_PFA;
  68.     LONG nb_fic_mv;
  69.     APTR mpool;
  70.     struct MinList ma_liste;
  71.     char *nom_prog;
  72. } MvPSF_Glo;
  73.  
  74.  
  75. /* === Section : Consts & Defines === */
  76.  
  77. /* Fichiers AFM */
  78. const char  AFMHeader[] = "StartFontMetrics";
  79. #define AFMHeadlong ((unsigned long)strlen(AFMHeader))
  80. const int PosAFM = 0;
  81. const char AFMFNStr[] = "FontName";
  82. const char AFMFHStr[] = "StartCharMetrics";
  83.  
  84.  
  85. /* Fichiers PFB */
  86. const char  PFBHeader[] = "\x80\x01";
  87. #define PFBHeadlong ((unsigned long)strlen(PFBHeader))
  88. const int PosPFB = 6;
  89. const char PFBFNStr[] = "/FontName";
  90. const char PFBFHStr[] = "eexec";
  91.  
  92.  
  93. /* ------ Fichiers PFA --- */
  94. const char  PFA1Header[] = "%!PS-AdobeFont";
  95. #define PFA1Headlong ((unsigned long)strlen(PFA1Header))
  96. const char  PFA2Header[] = "%!FontType";
  97. #define PFA2Headlong ((unsigned long)strlen(PFA2Header))
  98. const int PosPFA = 0;
  99. const char PFAFNStr[] = "/FontName";
  100. const char PFAFHStr[] = "eexec";
  101.  
  102.  
  103. /* ------ Memory Pool --- */
  104. const int NB_POOL=64;
  105. const int NB_PUDDLE=20;
  106.  
  107.  
  108. /* ------ Divers --- */
  109.  
  110. #ifdef __GNUC__
  111. const int LONG_BUFFER = 64; /* Le nombre d'octets lus au début de chaque fichier */
  112. const int LONGUEUR_NOM = 31; /* La longueur max du nom du programme */
  113. #else
  114. #define LONG_BUFFER 64
  115. #define LONGUEUR_NOM 31
  116. #endif
  117. char Template[] = "FILE/M/A,VERBOSE/S,ALL/S,STAT/S";
  118.  
  119.  
  120.  
  121. /* === Section : Prototypes === */
  122.  
  123. void traiter_fichier(MvPSF_Glo *contexte,Un_Fichier *fic);
  124. BOOL lecture_repertoire(MvPSF_Glo *contexte,struct FileInfoBlock *info,BPTR rep);
  125. BOOL ajoute_fichier(MvPSF_Glo *contexte,char *nom,Un_Fichier *fic);
  126. TYPE_FICHIER type_fichier(MvPSF_Glo *contexte,BPTR fic);
  127. BOOL recup_mot(MvPSF_Glo *contexte,BPTR fh,char *chaine,int longueur);
  128.  
  129.  
  130.  
  131. /* ------------------------------ main ------------------------------
  132.  
  133. Le programme principal.
  134.  
  135. */
  136.  
  137. int main(void)
  138. {
  139.     struct FileInfoBlock *info;
  140.     char mon_nom[32];
  141.     MvPSF_Args arguments;
  142.     MvPSF_Glo *contexte;
  143.     struct RDArgs *RDArgs;
  144.  
  145.     if (!GetProgramName(mon_nom,LONGUEUR_NOM))
  146.     {
  147.         strcpy(mon_nom,"MvPSF");
  148.     }
  149.  
  150.     Printf("\n\033[1m%s\033[m ©1996 Christophe Labouisse %s\n\n",mon_nom,__MA_VERSION__);
  151.  
  152.     arguments.verbose = FALSE;
  153.     arguments.all = FALSE;
  154.     arguments.stat = FALSE;
  155.  
  156.     RDArgs = ReadArgs(Template,(LONG *)&arguments,NULL);
  157.  
  158.     if (RDArgs)
  159.     {
  160.  
  161.         struct AnchorPath *AnchorPath;
  162.  
  163.         AnchorPath = (struct AnchorPath *)AllocVec(sizeof(struct AnchorPath),MEMF_PUBLIC|MEMF_CLEAR);
  164.  
  165.         if (AnchorPath)
  166.         {
  167.             AnchorPath->ap_BreakBits=SIGBREAKF_CTRL_C;
  168.             AnchorPath->ap_Strlen=0;
  169.  
  170.             info = AllocDosObjectTags(DOS_FIB,TAG_DONE,NULL);
  171.  
  172.             if (info)
  173.             {
  174.                 contexte = (MvPSF_Glo *)AllocVec(sizeof(MvPSF_Glo),MEMF_CLEAR);
  175.  
  176.                 if (contexte)
  177.                 {
  178.                     char **les_fichiers;
  179.                     BPTR ancien_rep;
  180.  
  181.                     contexte->all = arguments.all;
  182.                     contexte->verbose = arguments.verbose;
  183.                     contexte->stat = arguments.stat;
  184.                     contexte->nom_prog = mon_nom;
  185.  
  186.                     /* Allocation de la 'memory pool' pour la suite */
  187.                     contexte->mpool = CreatePool(MEMF_CLEAR,sizeof(Un_Fichier)*NB_POOL,sizeof(Un_Fichier)*NB_PUDDLE);
  188.  
  189.                     if (contexte->mpool)
  190.                     {
  191.                         struct MinNode *node;
  192.  
  193.                         les_fichiers = arguments.fichiers;
  194.  
  195.                         while (*les_fichiers)
  196.                         {
  197.                             LONG RetVal;
  198.  
  199.                             NewList((struct List *)&contexte->ma_liste);
  200.  
  201.                             if (contexte->verbose)
  202.                             {
  203.                                 Printf("Processing argument « \033[1m%s\033[m »\n",*les_fichiers);
  204.                             }
  205.  
  206.  
  207.                             for (RetVal = MatchFirst(*les_fichiers,AnchorPath) ; RetVal == 0 ; RetVal = MatchNext(AnchorPath))
  208.                             {
  209.                                 BPTR rep_courant;
  210.  
  211.                                 rep_courant = AnchorPath->ap_Current->an_Lock;
  212.  
  213.                                 if (AnchorPath->ap_Info.fib_DirEntryType > 0)
  214.                                 {
  215.                                     /* C'est un répertoire */
  216.  
  217.  
  218.                                     if (contexte->all)
  219.                                     {
  220.                                         if (!(AnchorPath->ap_Flags & APF_DIDDIR))
  221.                                         {
  222.                                             contexte->nb_dir_lues++;
  223.  
  224.                                             AnchorPath->ap_Flags |= APF_DODIR;
  225.  
  226.                                             if (contexte->verbose)
  227.                                             {
  228.                                                 Printf("Entering directory \033[1m%s\033[m\n",AnchorPath->ap_Info.fib_FileName);
  229.                                             }
  230.  
  231.                                         }
  232.                                         else if (contexte->verbose)
  233.                                         {
  234.                                             Printf("Exiting directory \033[1m%s\033[m\n",AnchorPath->ap_Info.fib_FileName);
  235.                                         }
  236.  
  237.  
  238.                                         AnchorPath->ap_Flags &= ~APF_DIDDIR;
  239.  
  240.                                     }
  241.                                     else
  242.                                     {
  243.                                         BOOL rv_lr = FALSE;
  244.                                         BPTR arg_courant;
  245.  
  246.                                         /* On modifie AnchorPath pour qu'il ne rentre pas dans le répertoire */
  247.                                         AnchorPath->ap_Flags |= APF_DIDDIR;
  248.                                         AnchorPath->ap_Flags &= ~APF_DODIR;
  249.  
  250.                                         ancien_rep = CurrentDir(rep_courant);
  251.  
  252.                                         arg_courant = Lock(AnchorPath->ap_Info.fib_FileName,ACCESS_READ);
  253.  
  254.                                         if (arg_courant)
  255.                                         {
  256.                                             CurrentDir(arg_courant);
  257.  
  258.                                             if (Examine(arg_courant,info))
  259.                                             {
  260.                                                 contexte->nb_dir_lues++;
  261.                                                 rv_lr = lecture_repertoire(contexte,info,arg_courant);
  262.                                             }
  263.                                             else
  264.                                             {
  265.                                                 Printf("%s : Can't examine %s - ",mon_nom,AnchorPath->ap_Current->an_Info.fib_FileName);
  266.                                                 PrintFault(IoErr(),NULL);
  267.                                             }
  268.  
  269.                                             UnLock(arg_courant);
  270.                                         }
  271.                                         else
  272.                                         {
  273.                                             Printf("%s : Can't lock %s - ",mon_nom,AnchorPath->ap_Current->an_Info.fib_FileName);
  274.                                             PrintFault(IoErr(),NULL);
  275.                                         }
  276.  
  277.                                         CurrentDir(ancien_rep);
  278.  
  279.                                         if (!rv_lr)
  280.                                         {
  281.                                             break;
  282.                                         }
  283.  
  284.                                     }
  285.  
  286.                                 }
  287.                                 else
  288.                                 {
  289.                                     /* Traitement d'un fichier */
  290.                                     Un_Fichier *f_tmp;
  291.  
  292.                                     f_tmp = AllocPooled(contexte->mpool,sizeof(Un_Fichier));
  293.  
  294.                                     if (f_tmp)
  295.                                     {
  296.  
  297.                                         ancien_rep = CurrentDir(rep_courant);
  298.  
  299.                                         if (ajoute_fichier(contexte,AnchorPath->ap_Info.fib_FileName,f_tmp))
  300.                                         {
  301.                                             f_tmp->repertoire = DupLock(AnchorPath->ap_Current->an_Lock);
  302.                                         }
  303.                                         else
  304.                                         {
  305.                                             FreePooled(contexte->mpool,f_tmp,sizeof(Un_Fichier));
  306.                                         }
  307.  
  308.                                         CurrentDir(ancien_rep);
  309.  
  310.                                     }
  311.                                     else
  312.                                     {
  313.                                         PrintFault(ERROR_NO_FREE_STORE,mon_nom);
  314.                                         break;
  315.                                     }
  316.  
  317.                                 }
  318.  
  319.                             } /* for (RetVal ...) */
  320.  
  321.                             MatchEnd(AnchorPath);
  322.  
  323.                             if (RetVal != ERROR_NO_MORE_ENTRIES)
  324.                             {
  325.                                 Printf("%s : %s - ",mon_nom,*les_fichiers);
  326.                                 PrintFault(RetVal,NULL);
  327.  
  328.                                 /* Lorsqu'un fichier ou un répertoire n'existe pas
  329.                                  * on passe au suivant. Dans les autres cas on sort */
  330.                                 if ((RetVal != ERROR_OBJECT_NOT_FOUND) &&
  331.                                     (RetVal != ERROR_DEVICE_NOT_MOUNTED))
  332.                                 {
  333.                                     break;
  334.                                 }
  335.  
  336.                             }
  337.  
  338.                             les_fichiers++;
  339.  
  340.                             for (node = contexte->ma_liste.mlh_Head ; node->mln_Succ ; node = node->mln_Succ)
  341.                             {
  342.                                 Un_Fichier *f_tmp;
  343.  
  344.                                 f_tmp = (Un_Fichier *)node;
  345.                                 traiter_fichier(contexte,f_tmp);
  346.                             }
  347.  
  348.                         } /* while (*les_fichiers) */
  349.  
  350.                         if (contexte->stat)
  351.                         {
  352.                             Printf("\n%s statistics :\n",contexte->nom_prog);
  353.                             Printf("\t%ld Directory(ies) entered\n",contexte->nb_dir_lues);
  354.                             Printf("\t%ld File(s) processed\n",contexte->nb_fic_lus);
  355.                             Printf("\t%ld AFM File(s) found\n",contexte->nb_AFM);
  356.                             Printf("\t%ld PFA File(s) found\n",contexte->nb_PFA);
  357.                             Printf("\t%ld PFB File(s) found\n",contexte->nb_PFB);
  358.                             Printf("\t%ld File(s) renamed\n\n",contexte->nb_fic_mv);
  359.                         }
  360.  
  361.  
  362.                         DeletePool(contexte->mpool);
  363.                     }
  364.                     else
  365.                     {
  366.                         Printf("%s : Can't Create memory pool - ",mon_nom);
  367.                         PrintFault(ERROR_NO_FREE_STORE,NULL);
  368.                     }
  369.  
  370.                     FreeVec(contexte);
  371.                 }
  372.                 else
  373.                 {
  374.                     PrintFault(ERROR_NO_FREE_STORE,mon_nom);
  375.                 }
  376.  
  377.  
  378.                 FreeDosObject(DOS_FIB,info);
  379.  
  380.             } /* FileInfoBlock */
  381.             else
  382.             {
  383.                 Printf("%s : FileInfoBlock's Allocation - ",mon_nom);
  384.                 PrintFault(ERROR_NO_FREE_STORE,NULL);
  385.             }
  386.  
  387.             FreeVec((APTR)AnchorPath);
  388.  
  389.         } /* AnchorPath */
  390.         else
  391.         {
  392.             Printf("%s : AnchorPath's Allocation - ",mon_nom);
  393.             PrintFault(ERROR_NO_FREE_STORE,NULL);
  394.         }
  395.  
  396.         FreeArgs(RDArgs);
  397.  
  398.     }
  399.     else
  400.     {
  401.         PrintFault(IoErr(),mon_nom);
  402.     }
  403.  
  404. } /* --- main() --- */
  405.  
  406.  
  407.  
  408. /* ------------------------------ traiter_fichier ------------------------------
  409.  
  410.  Commentaire: Traitement d'un fichier. Récupération du nom et renommage si nécessaire
  411.  
  412. */
  413.  
  414. void traiter_fichier(MvPSF_Glo *contexte,Un_Fichier *fic)
  415. {
  416.     BPTR fh;
  417.     BPTR ancien_rep;
  418.  
  419.     ancien_rep = CurrentDir(fic->repertoire);
  420.  
  421.     fh = Open(fic->nom,MODE_OLDFILE);
  422.  
  423.     if (fh)
  424.     {
  425.         char chaine[256];
  426.  
  427.         Seek(fh,fic->PosDebut,OFFSET_BEGINNING);
  428.  
  429.         do  /* Recherche du nom de la fonte dans le fichier */
  430.         {
  431.             if (recup_mot(contexte,fh,chaine,sizeof(chaine)))
  432.             {
  433.                 if (!strcmp(chaine,fic->fontname))
  434.                 {
  435.                     if (recup_mot(contexte,fh,chaine,sizeof(chaine)))
  436.                     {
  437.                         char tmp_nom[108];
  438.                         int lchaine = strlen(chaine)-1;
  439.  
  440.                         /* On filtre le dernier caractère si c'est ) */
  441.                         if (chaine[lchaine] == ')')
  442.                         {
  443.                             chaine[lchaine] = '\0';
  444.                         }
  445.  
  446.  
  447.                         /* On filtre le premier caractère si c'est ( ou / */
  448.                         if ((*chaine == '/') || (*chaine == '('))
  449.                         {
  450.                             strcpy(tmp_nom,chaine+1);
  451.                         }
  452.                         else
  453.                         {
  454.                             strcpy(tmp_nom,chaine);
  455.                         }
  456.  
  457.                         strcat(tmp_nom,fic->type);
  458.  
  459.                         if (strncmp(fic->nom,tmp_nom,LONGUEUR_NOM - 1))
  460.                         {
  461.                             if (Rename(fic->nom,tmp_nom))
  462.                             {
  463.                                 contexte->nb_fic_mv++;
  464.                                 Printf("Renaming \033[33m%s\033[m to \033[33m%s\033[m\n",fic->nom,tmp_nom);
  465.                             }
  466.                             else
  467.                             {
  468.                                 Printf("%s : %s - ",contexte->nom_prog,fic->nom);
  469.                                 PrintFault(IoErr(),NULL);
  470.                             }
  471.  
  472.                         }
  473.                         else
  474.                         {
  475.                             Printf("%s \033[1mOK\033[m\n",fic->nom);
  476.                         }
  477.  
  478.                         break;
  479.                     }
  480.                     else
  481.                     {
  482.                         Printf("%s : %s - ",contexte->nom_prog,fic->nom);
  483.                         PrintFault(IoErr(),NULL);
  484.                         break;
  485.                     }
  486.  
  487.                 }
  488.                 else
  489.                 {
  490.                     if (!strcmp(chaine,fic->finhead))
  491.                     {
  492.                         Printf("Can't find \033[1m%s\033[m in \033[33m%s\033[m\n",fic->fontname,fic->nom);
  493.                         break;
  494.                     }
  495.  
  496.                 }
  497.  
  498.             }
  499.             else
  500.             {
  501.                 LONG erreur = IoErr();
  502.  
  503.                 if (erreur)
  504.                 {
  505.                     Printf("%s : %s - ",contexte->nom_prog,fic->nom);
  506.                     PrintFault(IoErr(),NULL);
  507.                 }
  508.                 else
  509.                 {
  510.                     Printf("Can't find %s in %s\n",fic->fontname,fic->nom);
  511.                 }
  512.  
  513.                 break;
  514.             }
  515.  
  516.         } while(1);
  517.  
  518.         Close(fh);
  519.     }
  520.     else
  521.     {
  522.         Printf("%s : %s - ",contexte->nom_prog,fic->nom);
  523.         PrintFault(IoErr(),NULL);
  524.     }
  525.  
  526.     CurrentDir(ancien_rep); /* On revient au répertoire initial */
  527.     UnLock(fic->repertoire);/* On libère le "Lock" au répertoire du fichier */
  528.  
  529. } /* --- traiter_fichier() --- */
  530.  
  531.  
  532.  
  533. /* --------------------------------- recup_mot ---------------------------------
  534.  
  535.  Commentaire: Récupère le mot suivant du fichier fh.
  536.  
  537.  fh : fichier.
  538.  chaine : buffer dans lequel sera mis le mot.
  539.  longueur : longueur de 'chaine'.
  540.  
  541. */
  542.  
  543. BOOL recup_mot(MvPSF_Glo *contexte,BPTR fh,char *chaine,int longueur)
  544. {
  545.     BOOL rv;
  546.     int courant = 0;
  547.     longueur--;
  548.  
  549.     do
  550.     {
  551.         LONG buffer = FGetC(fh);
  552.  
  553.         if (buffer < 0)
  554.         {
  555.             rv = FALSE;
  556.             break;
  557.         }
  558.  
  559.         if (isspace(buffer))
  560.         {
  561.             chaine[courant] = '\0';
  562.             rv = TRUE;
  563.             break;
  564.         }
  565.         else
  566.         {
  567.             chaine[courant] = buffer;
  568.             courant++;
  569.  
  570.             if (courant >= longueur)
  571.             {
  572.                 chaine[longueur] = '\0';
  573.                 Printf("Error while parsing line to long\n\t-> (%s)\n",chaine);
  574.                 rv = FALSE;
  575.                 break;
  576.             }
  577.         }
  578.     } while(1);
  579.  
  580.     return rv;
  581.  
  582. } /* -- recup_mot() --- */
  583.  
  584.  
  585.  
  586. /* --------------------------------- lecture_repertoire ---------------------------------
  587.  
  588.  Commentaire: Ajoute les fichiers du répertoire à la liste.
  589.  
  590. */
  591.  
  592. BOOL lecture_repertoire(MvPSF_Glo *contexte,struct FileInfoBlock *info,BPTR rep)
  593. {
  594.     BOOL rv;
  595.  
  596.     Un_Fichier *f_tmp = AllocPooled(contexte->mpool,sizeof(Un_Fichier));
  597.  
  598.     if (f_tmp)
  599.     {
  600.         do
  601.         {
  602.  
  603.             if (!ExNext(rep,info))
  604.             {
  605.                 long erreur;
  606.  
  607.                 erreur = IoErr();
  608.  
  609.                 if (erreur != ERROR_NO_MORE_ENTRIES)
  610.                 {
  611.                     Printf("%s : While examining directory - ",contexte->nom_prog);
  612.                     PrintFault(erreur,NULL);
  613.                 }
  614.  
  615.                 break;
  616.             }
  617.  
  618.             if (info->fib_DirEntryType < 0)
  619.             {
  620.                 if (ajoute_fichier(contexte,info->fib_FileName,f_tmp))
  621.                 {
  622.                     /* On ajoute le répertoire au fichier qui viens d'être ajouté */
  623.                     f_tmp->repertoire = DupLock(rep);
  624.  
  625.                     f_tmp = AllocPooled(contexte->mpool, sizeof(Un_Fichier));
  626.  
  627.                     if (!f_tmp)
  628.                     {
  629.                         PrintFault(ERROR_NO_FREE_STORE,contexte->nom_prog);
  630.                         break;
  631.                     }
  632.  
  633.                 }
  634.  
  635.             }
  636.             else if (contexte->verbose)
  637.             {
  638.                 Printf("\t\033[1m%s\033[m is a directory\n",info->fib_FileName);
  639.             }
  640.  
  641.         } while(1);
  642.     }
  643.     else
  644.     {
  645.         PrintFault(ERROR_NO_FREE_STORE,contexte->nom_prog);
  646.     }
  647.  
  648.     if (f_tmp)
  649.     {
  650.         FreePooled(contexte->mpool,f_tmp,sizeof(Un_Fichier));
  651.         rv = TRUE;
  652.     }
  653.     else
  654.     {
  655.         rv = FALSE;
  656.     }
  657.  
  658.     return rv;
  659. } /* --- lecture_repertoire --- */
  660.  
  661.  
  662.  
  663. /* --------------------------------- ajoute_fichier ---------------------------------
  664.  
  665.  Commentaire: Renvoie TRUE si le fichier et d'un type connu et rempli la structure
  666.  fournie. Renvoie FALSE sinon.
  667.  Ajoute le fichier à la liste.
  668.  
  669. */
  670.  
  671. BOOL ajoute_fichier(MvPSF_Glo *contexte,char *nom,Un_Fichier *fic)
  672. {
  673.     BOOL rv = TRUE;
  674.     BPTR fichier;
  675.  
  676.     if (contexte->verbose)
  677.     {
  678.         Printf("\tProcessing \033[1m%s\033[m\n",nom);
  679.     }
  680.  
  681.     fichier = Open(nom,MODE_OLDFILE);
  682.  
  683.     if (fichier)
  684.     {
  685.  
  686.         contexte->nb_fic_lus++;
  687.  
  688.         switch (type_fichier(contexte,fichier))
  689.         {
  690.             case (TYF_AFM) :
  691.             {
  692.                 fic->PosDebut = PosAFM;
  693.                 strcpy(fic->fontname,AFMFNStr);
  694.                 strcpy(fic->type,".AFM");
  695.                 strcpy(fic->finhead,AFMFHStr);
  696.  
  697.                 if (contexte->verbose)
  698.                 {
  699.                     Printf("\t\t\033[1m%s\033[m is a AFM file\n",nom);
  700.                 }
  701.  
  702.                 contexte->nb_AFM++;
  703.                 break;
  704.             }
  705.  
  706.             case (TYF_PFA) :
  707.             {
  708.                 fic->PosDebut = PosPFA;
  709.                 strcpy(fic->fontname,PFAFNStr);
  710.                 strcpy(fic->type,".PFA");
  711.                 strcpy(fic->finhead,PFAFHStr);
  712.  
  713.                 if (contexte->verbose)
  714.                 {
  715.                     Printf("\t\t\033[1m%s\033[m is a PFA file\n",nom);
  716.                 }
  717.  
  718.                 contexte->nb_PFA++;
  719.                 break;
  720.             }
  721.  
  722.             case (TYF_PFB) :
  723.             {
  724.                 fic->PosDebut = PosPFB;
  725.                 strcpy(fic->fontname,PFBFNStr);
  726.                 strcpy(fic->type,".PFB");
  727.                 strcpy(fic->finhead,PFBFHStr);
  728.  
  729.                 if (contexte->verbose)
  730.                 {
  731.                     Printf("\t\t\033[1m%s\033[m is a PFB file\n",nom);
  732.                 }
  733.  
  734.                 contexte->nb_PFB++;
  735.                 break;
  736.             }
  737.  
  738.             case (TYF_NON) :
  739.             {
  740.                 if (contexte->verbose)
  741.                 {
  742.                     Printf("\t\t\033[1m%s\033[m doesn't seem to belong to any known type\n",nom);
  743.                 }
  744.  
  745.                 rv = FALSE;
  746.                 break;
  747.             }
  748.  
  749.             case (TYF_ERR) :
  750.             {
  751.                 LONG code_erreur = IoErr();
  752.  
  753.                 /* Si le code erreur est nul c'est probablement que le fichier est de longueur nulle */
  754.                 if (code_erreur)
  755.                 {
  756.                     Printf("%s : Error reading file %s - ",contexte->nom_prog,nom);
  757.                     PrintFault(IoErr(),NULL);
  758.                 }
  759.                 else if (contexte->verbose)
  760.                 {
  761.                     Printf("\t\t\033[1m%s\033[m doesn't seem to belong to any known type\n",nom);
  762.                 }
  763.  
  764.                 rv = FALSE;
  765.                 break;
  766.             }
  767.         }
  768.  
  769.         if (rv)
  770.         {
  771.             strcpy(fic->nom,nom);
  772.             AddTail((struct List *)&contexte->ma_liste,(struct Node *)fic);
  773.         }
  774.  
  775.         Close(fichier);
  776.  
  777.     }
  778.     else
  779.     {
  780.         Printf("%s : Error can't open file %s - ",contexte->nom_prog,nom);
  781.         PrintFault(IoErr(),NULL);
  782.         rv = FALSE;
  783.     }
  784.  
  785.     return rv;
  786.  
  787. } /* --- ajoute_fichier --- */
  788.  
  789.  
  790.  
  791. /* --------------------------------- type_fichier ---------------------------------
  792.  
  793.  Commentaire: Détermine le type du fichier.
  794.  
  795. */
  796.  
  797. TYPE_FICHIER type_fichier(MvPSF_Glo *contexte,BPTR fichier)
  798. {
  799.     char buffer[LONG_BUFFER];
  800.     TYPE_FICHIER ret_val;
  801.  
  802.     if (Read(fichier,buffer,sizeof(buffer)) > 0)
  803.     {
  804.         if (!memcmp(buffer,AFMHeader,AFMHeadlong))
  805.         {
  806.             ret_val = TYF_AFM;
  807.         }
  808.         else if (!memcmp(buffer,PFBHeader,PFBHeadlong) &&
  809.                  (!memcmp(buffer+PosPFB,PFA1Header,PFA1Headlong) ||
  810.                   !memcmp(buffer+PosPFB,PFA2Header,PFA2Headlong)))
  811.         {
  812.             ret_val = TYF_PFB;
  813.         }
  814.         else if (!memcmp(buffer,PFA1Header,PFA1Headlong) ||
  815.                  !memcmp(buffer,PFA2Header,PFA2Headlong))
  816.         {
  817.             ret_val = TYF_PFA;
  818.         }
  819.         else
  820.         {
  821.             ret_val = TYF_NON;
  822.         }
  823.  
  824.     }
  825.     else
  826.     {
  827.         ret_val = TYF_ERR;
  828.     }
  829.  
  830.     return ret_val;
  831. } /* --- type_fichier --- */
  832.  
  833.  
  834. /* ---
  835.  * $Log: MvPSF.c,v $
  836.  * Revision 1.4  1996/04/10  21:30:16  Christophe_Labouisse
  837.  * Correction RCS Version -> Revision
  838.  *
  839.  * Revision 1.3  1996/04/10  21:25:37  Christophe_Labouisse
  840.  * Ajout des statistiques.
  841.  * Utilisation de RCS pour le numéro de version.
  842.  *
  843.  * Revision 1.2  1996/04/07  14:47:27  LABOUISSE_Christophe
  844.  * Ajout des mots clés VERBOSE et ALL
  845.  * Nouvelle utilisation des arguments permettant maintenant d'avoir plusieurs
  846.  * fichiers ou répertoires traités en une seule commande.
  847.  *
  848.  * Revision 1.1  1996/03/23  22:46:43  LABOUISSE_Christophe
  849.  * Initial revision
  850.  *
  851. } /* --- */
  852.  
  853.